package com.tiger.project.service.impl;

import java.math.BigDecimal;
import java.util.List;

import com.tiger.common.utils.DateUtils;
import com.tiger.common.utils.StringUtils;
import com.tiger.project.domain.AssetReceiptAllocation;
import com.tiger.project.domain.ContractBill;
import com.tiger.project.mapper.AssetReceiptAllocationMapper;
import com.tiger.project.mapper.ContractBillMapper;
import com.tiger.project.service.IAssetReceiptAllocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 【租金分配收款信息】Service业务层处理
 *
 * @author standard
 * @date 2022-10-09
 */
@Service
public class AssetReceiptAllocationServiceImpl implements IAssetReceiptAllocationService {
    @Autowired
    private AssetReceiptAllocationMapper assetReceiptAllocationMapper;
    @Autowired
    private ContractBillMapper billMapper;

    /**
     * 查询【租金分配收款信息】
     *
     * @param id 【租金分配收款信息】主键
     * @return 【租金分配收款信息】
     */
    @Override
    public AssetReceiptAllocation selectAssetReceiptAllocationById(Long id) {
        return assetReceiptAllocationMapper.selectAssetReceiptAllocationById(id);
    }

    /**
     * 查询【租金分配收款信息】列表
     *
     * @param assetReceiptAllocation 【租金分配收款信息】
     * @return 【租金分配收款信息】
     */
    @Override
    public List<AssetReceiptAllocation> selectAssetReceiptAllocationList(AssetReceiptAllocation assetReceiptAllocation) {
        return assetReceiptAllocationMapper.selectAssetReceiptAllocationList(assetReceiptAllocation);
    }

    /**
     * 新增【租金分配收款信息】
     *
     * @param assetReceiptAllocation 【租金分配收款信息】
     * @return 结果
     */
    @Override
    public int insertAssetReceiptAllocation(AssetReceiptAllocation assetReceiptAllocation) {
        //本期应付金额 = 本期实收金额 + 本期减免金额  账单状态就会改为已缴清
        if (StringUtils.isNotNull(assetReceiptAllocation.getBillStatus())){
            ContractBill bill = new ContractBill();
            bill.setId(assetReceiptAllocation.getBillId());
            bill.setBillStatus(assetReceiptAllocation.getBillStatus());
            billMapper.updateContractBill(bill);
        }
        assetReceiptAllocation.setAllocationTime(DateUtils.getNowDate());
        return assetReceiptAllocationMapper.insertAssetReceiptAllocation(assetReceiptAllocation);
    }

    /**
     * 修改【租金分配收款信息】
     *
     * @param assetReceiptAllocation 【租金分配收款信息】
     * @return 结果
     */
    @Override
    public int updateAssetReceiptAllocation(AssetReceiptAllocation assetReceiptAllocation) {
        return assetReceiptAllocationMapper.updateAssetReceiptAllocation(assetReceiptAllocation);
    }

    /**
     * 批量删除【租金分配收款信息】
     *
     * @param ids 需要删除的【租金分配收款信息】主键
     * @return 结果
     */
    @Override
    public int deleteAssetReceiptAllocationByIds(Long[] ids) {
        return assetReceiptAllocationMapper.deleteAssetReceiptAllocationByIds(ids);
    }

    /**
     * 删除【租金分配收款信息】信息
     *
     * @param id 【租金分配收款信息】主键
     * @return 结果
     */
    @Override
    public int deleteAssetReceiptAllocationById(Long id) {
        return assetReceiptAllocationMapper.deleteAssetReceiptAllocationById(id);
    }



}
